<template>
  <view class="recommend-box">
    <view class="course-box" v-if="hasImg">
      <image class="course-img" mode="widthFix" :src="imgObj.imageLinks" alt="" @click="urlTarget(imgObj)"></image>
    </view>
    <view class="add-btn-box" v-if="hasBtn">
      <image class="add-btn" mode="widthFix" :src="btnObj.imageLinks" alt="" @click="urlTarget(btnObj)"></image>
    </view>
  </view>
</template>
<script>
import { appProductId } from "@/http/env.js";
import { getProductConfigApi } from "@/http/api.js";
export default {
  name: 'ProductGetcodeCourse',
  data() {
    return {
      imgPositionId: 13,
      btnPositionId: 14,
      hasImg: false,
      hasBtn: false,
      imgObj: {},
      btnObj: {}
    }
  },
  mounted() {
      // 获取产品线配置
      getProductConfigApi({
        parentId: appProductId,
        positionType: this.imgPositionId
      }).then(res => {
        if (res.code === 200 && res.data.length != 0) {
          this.hasImg = true;
          this.imgObj = res.data[0];
        }else{
          this.hasImg = false;
        }
      })
      // 获取产品线配置
      getProductConfigApi({
        parentId: appProductId,
        positionType: this.btnPositionId
      }).then(res => {
        if (res.code === 200 && res.data.length != 0) {
          this.hasBtn = true;
          this.btnObj = res.data[0];
        }else{
          this.hasBtn = false;
        }
      })
  },
  methods: {
    urlTarget(row) {
      if (row.skipLinks) {
        if (row.isOut == 1) {
          window.location.href = row.skipLinks;
          return
        }else{
          uni.navigateTo({
            url: row.skipLinks
          });
        }
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.course-box {
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  margin-bottom: 17rpx;
  .course-img {
    width: 601rpx;
	  height: 241rpx;
  }
}
.add-btn-box {
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  margin-bottom: 17rpx;
  .add-btn {
    width: 568rpx;
    height: 105rpx;
    animation-name: scaleDraw;/*关键帧名称*/
    animation-timing-function: ease-in-out;/*动画的速度曲线*/
    animation-iteration-count: infinite;/*动画播放的次数*/
    animation-duration:0.5s;/*动画所花费的时间*/
  }
}
</style>